/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 3

Using:	Debug.h
		Manager.h
		Comparer.h
		stdio.h
		hw_code\Hw3Types.h
		hw_code\Bmp24LineReader.h
		

Description:
This module contains debug functions for this program

oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/


#define _CRT_SECURE_NO_WARNINGS

#include "Debug.h"
#include "Manager.h"
#include "Comparer.h"
#include <stdio.h>

#include "hw_code\Hw3Types.h"
#include "hw_code\Bmp24LineReader.h"


// Saving the raw image (For use in matlab later)
void SavePicture()
{
	int x, y;
	FILE* file;

	file = fopen("grayscale.bmp", "wb");

	for (y = 0; y < GlobalPicture.PictureHeight; y++)
	{
		for (x = 0; x < GlobalPicture.PictureWidth; x++)
		{
			fwrite(&(GlobalPicture.Picture[y][x]), 1, 1, file);
		}
	}

	fclose(file);
}

void GenerateDebugFiles(char* prefix)
{
	FILE* debugFile;

	char facebookFilename[MAX_LINE_LEN];
	char debugFilename[MAX_LINE_LEN];

	strcpy(facebookFilename, prefix);
	strcat(facebookFilename, "_facebook.csv");
	strcpy(debugFilename, prefix);
	strcat(debugFilename, "_debug.txt");

	// Save the facebook
	SaveFacebookToFile(facebookFilename);

	// And some debug info
	debugFile = fopen(debugFilename, "w");

	fprintf(debugFile, "Number of faces: %d", FacesCount());

	fclose(debugFile);

}

void PrintAreas(PArea areas, int vertCount, int horizCount)
{
	int y,x;
	int index = 0;
	PArea area;

	// Now Initialize the areas
	for (y = 0; y < vertCount; y++)
	{
		for (x = 0; x < horizCount; x++)
		{
			printf("|-------------|", index);
		}
		printf("\n");
		for (x = 0; x < horizCount; x++)
		{
			index = (y * horizCount) + x;
			area = &areas[index];
			printf("|      %02d     |", index);
		}
		printf("\n");
		for (x = 0; x < horizCount; x++)
		{
			index = (y * horizCount) + x;
			area = &areas[index];
			printf("|  (%03d,%03d)  |", area->X, area->Y);
		}
		printf("\n");
		for (x = 0; x < horizCount; x++)
		{
			index = (y * horizCount) + x;
			area = &areas[index];
			printf("|  [%03d,%03d]  |", area->Width, area->Height);
		}
		printf("\n");
		for (x = 0; x < horizCount; x++)
		{
			printf("|-------------|", index);
		}
		printf("\n");
	}
	printf("\n");
}